package com.example.abc.web.account;

import com.example.abc.common.Constants;
import com.example.abc.common.DataTableRequest;
import com.example.abc.common.DataTableResponse;
import com.example.abc.dto.account.AuthorityTreeDto;
import com.example.abc.entity.Account;
import com.example.abc.entity.Authority;
import com.example.abc.service.AccountService;
import com.example.abc.service.AuthorityService;
import com.example.abc.util.JsonUtil;
import com.example.abc.web.IndexController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by Peter on 2018/4/27.
 */
@Controller
public class AuthoritiyController {
    public static final Logger logger = LoggerFactory.getLogger(IndexController.class);
    @Autowired
    private AuthorityService authorityService;

    @RequestMapping(value = "/authorities", method = {RequestMethod.GET})
    public String login(Model model) {
        List<AuthorityTreeDto> list = authorityService.getAllAuthTree();
        model.addAttribute("data",JsonUtil.toJson(list));
        return "account/authorities";
    }

    @RequestMapping(value = "/authorities", method = {RequestMethod.POST})
    @ResponseBody
    public List<AuthorityTreeDto> accountData(HttpServletRequest request, Model model) {
        List<AuthorityTreeDto> list = authorityService.getAllAuthTree();
        return list;
    }
}
